package com.github.util;

import java.util.ArrayList;
import java.util.List;

public class Main2 {
	public static void main(String[] args) {
		List<Person> persons = new ArrayList<Person>();
		Person person1 = new Person();
		person1.setName("张三");
		person1.setSex("男");
		persons.add(person1);
		Person person2 = new Person();
		person2.setName("李四");
		person2.setSex("女");
		persons.add(person2);
		// 创建动态 Bean 实例
		DynaBean dynaBean = new DynaBean(Person.class);
		for (Person person : persons) {
			System.out.println(String.format("[name=%s, sex=%s]",
					// 获取 Bean 对象的 name 属性的值
					dynaBean.getFieldValue(person, "name"),
					// 获取 Bean 对象的 sex 属性的值
					dynaBean.getFieldValue(person, "sex")));
		}
	}
}
